package com.ab;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;

/**
 * Created by IntelliJ IDEA.
 * User: pvg
 * Date: 10/21/11
 * Time: 8:02 AM
 */
public class Cube {
    public static final String dimensionRequest = "Введите размерность куба: ";
    public static final String help = "Для выхода введиле: quit";
    private final ArrayList<BinaryPoint> binaryPoints = new ArrayList<BinaryPoint>();

    public Cube(int dimension) {
        BinaryPoint point = BinaryPoint.createZeroPoint(dimension);

        do {
            binaryPoints.add(point);
            point = point.next();
        } while (point != null);
    }

    public void list() {
        for (BinaryPoint p : binaryPoints) {
            System.out.println(Arrays.toString(p.getCoords()));
        }
    }

    public int getVerticalsCount() {
        return binaryPoints.size();
    }


    public int getEdgesCount() {
        int edgesCount = 0;
        for (BinaryPoint point : binaryPoints) {
            for (boolean coord : point.getCoords()) {
                if (!coord) {
                    edgesCount++;
                }
            }
        }
        return edgesCount;
    }

    public static void main(String[] args) throws IOException {

        InputStreamReader inputStreamReader = new InputStreamReader ( System.in );
        BufferedReader stdin = new BufferedReader ( inputStreamReader );
        boolean hasRequestedQuit = false;
        String line = null;
        System.out.println(help);
        System.out.println(dimensionRequest);
        while (!hasRequestedQuit) {
            System.out.print("размерность: ");
            line = stdin.readLine();
            if (line.matches("quit")) {
                System.out.println("Пока-пока");
                hasRequestedQuit = true;
                break;
            }
            if (line.matches("^([1-9])+([0-9])?$") )  {
                try
                {
                    int dimension = Integer.parseInt(line);
                    Cube cube = new Cube(dimension);
                    System.out.println("Количество вершин: " + cube.getVerticalsCount());
                    System.out.println("Количество ребер: " + cube.getEdgesCount());


                }  catch (NumberFormatException e){
                    System.out.println("Dimension must be a natural number");

                }
            } else {

                if (line.matches("(.*)хуй(.*)")) {
                    System.out.println("Сам хуй...");
                }
                System.out.println("Не балуйтесь, размерность должна быть натуральным числом");
            }

        }



    }
}
